<template>
    <div class="mod-config">
      <el-form :inline="true" :model="dataForm" >
        <el-form-item>
          <el-input v-model="dataForm.name" placeholder="商家姓名" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.account" placeholder="商家账号" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.contactPhoneNumber" placeholder="手机号码" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.categoryOperateId" placeholder="请选择类型">
              <el-option  v-for="item in operateList" :key="item.id" :label="item.categoryName" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.status" placeholder="请选择状态">
            <el-option v-for="item in optionTwo" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">查询</el-button>
          <el-button type="primary" @click="resetting()">重置</el-button>
          <!-- <el-button v-if="isAuth('course:coursetype:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
        </el-form-item>
        <el-form-item>
          <!-- <el-button type="primary" @click="jobBtn()">职务管理</el-button> -->
          <el-button type="primary" @click="addOrUpdateHandle()" v-if="isAuth('sys:user:add')">开户</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle"
        style="width: 100%">
        <el-table-column type="selection" header-align="center" align="center" width="50">
        </el-table-column>
        <el-table-column  prop="account"  header-align="center" align="center" label="账号"></el-table-column>
        <el-table-column prop="createTime" header-align="center" align="center" label="开户时间">
          <template slot-scope="scope">
            <span>{{
              getStrTime(scope.row.createTime)
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="licenseNumber"  header-align="center" align="center" label="营业执照编号"></el-table-column>
        <el-table-column prop="name"  header-align="center" align="center" label="商家名称"></el-table-column>
        <el-table-column prop="name" header-align="center" align="center" label="姓名"></el-table-column>
        <el-table-column prop="contactPhoneNumber" header-align="center" align="center" label="手机号码"></el-table-column>
        <el-table-column header-align="center" align="center" label="联系地址">
          <template slot-scope="scope">
              <span>{{scope.row.province+scope.row.city+scope.row.address+scope.row.area}}</span>
          </template>
        </el-table-column>
        <el-table-column header-align="center" align="center" label="类型">
          <template slot-scope="scope">
            <div v-for="(item,index) in scope.row.businessCategoryOperateList" :key="index">
              <span v-if="item.selectFlag==1">{{item.categoryName}}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="checkName" header-align="center" align="center" label="跟进人"></el-table-column>
        <el-table-column prop="status" header-align="center" align="center" label="状态">
          <template slot-scope="scope">
              <span >{{scope.row.status==0?'禁用':'启用'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="openingChannel" header-align="center" align="center" label="开户渠道"></el-table-column>
        <el-table-column fixed="right" header-align="center" align="center" width="200" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="uStatus(scope.row.id, 0)"
              v-if="scope.row.status == 1 && isAuth('sys:user:disable')">禁用</el-button>
            <el-button type="text" size="small" @click="uStatus(scope.row.id, 1)"
              v-if="scope.row.status == 0 && isAuth('sys:user:enable')">启用</el-button>
            <el-button v-if="isAuth('sys:user:update')" type="text" size="small"
              @click="addOrUpdateHandle(scope.row.id)">编辑</el-button>
            <el-button v-if="isAuth('sys:user:password:update')" type="text" size="small"
              @click="upwd(scope.row.id)">重置密码</el-button>
            <el-button type="text" size="small" v-if="isAuth('sys:user:delete')"
              @click="deleteHandle(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      <StaffAdmin v-if="addOrUpdateVisibles" ref="staffAdmin" @refreshDataList="getDataList"></StaffAdmin>
      <UpPasswordPop v-if="ispasswordPop" ref="passwordPop" @refreshDataList="getDataList"></UpPasswordPop>
      <el-dialog title="邀请码 / 世界波账号" :visible.sync="dialogVisible3" width="30%" :before-close="handleClose3">
        <div class="drCodeCont" v-for="(item,index) in info.sjbAccountList" :key="index">
          {{item.promotionCode}} / {{item.sjbAccount}}
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible3 = false">取消</el-button>
        </span>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import AddOrUpdate from './staff-add-or-update'
  import StaffAdmin from './staffAdmin'
  import UpPasswordPop from './upPasswordPop'
  export default {
    data () {
      return {
        dialogVisible3: false,
        ispasswordPop: false,
        dataForm: {
          name: '',
          account: '',
          contactPhoneNumber:'',
          categoryOperateId:'',
          status: null
        },
        info: {},
        operateList: [
          {
            value: null,
            label: '全部'
          },
          {
            value: true,
            label: '1'
          },
          {
            value: false,
            label: '2'
          },
          {
            value: false,
            label: '3'
          }
        ],
        optionTwo: [
          {
            value: null,
            label: '全部'
          },
          {
            value: 1,
            label: '启用'
          },
          {
            value: 0,
            label: '禁用'
          }
        ],
        addOrUpdateVisibles: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate,
      StaffAdmin,
      UpPasswordPop
    },
    activated () {
      this.getDataList()
      this.getJobList()
    },
    methods: {
      getJobList() {
        this.$http({
          url: this.$http.adornUrl(`/common/category/operate/list`),
          method: "get",
          params: this.$http.adornParams(),
        }).then(({ data }) => {
          if (data && data.code === "200") {
            this.operateList = data.list;
          }
        });
      },
      handleClose3 () {
        this.dialogVisible3 = false
      },
      viewSjbAccount (item) {
        this.info = item
        this.dialogVisible3 = true
      },
      uStatus (id, e) {
        this.$confirm(
          ` ${e == 1
            ? '账户启用之后，该账户可正常登录平台。'
            : '账户停用之后，该用户将无法登录平台。'
          }`,
          `确定${e == 1 ? '启用' : '禁用'} 该用户账户？`,
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'danger'
          }
        ).then(() => {
          this.$http({
            url: this.$http.adornUrl(e == 1 ? '/admin/business/enable' : '/admin/business/disable'),
            method: 'post',
            data: this.$http.adornData({ id: id}, false)
          }).then(({ data }) => {
            if (data && data.code === '200') {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                  this.dialogVisible = false
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      resetting () {
        this.dataForm = {
          name: '',
          account: '',
          contactPhoneNumber:'',
          categoryOperateId:'',
          status: null
        }
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.$http({
          url: this.$http.adornUrl(`/admin/business/page`),
          method: 'post',
          data: this.$http.adornData({
            pageNum: this.pageIndex,
            pageSize: this.pageSize,
            name: this.dataForm.name,
            account: this.dataForm.account,
            categoryOperateId:this.dataForm.categoryOperateId,
            status: this.dataForm.status,
            contactPhoneNumber: this.dataForm.contactPhoneNumber
          })
        }).then(({ data }) => {
          if (data && data.code === '200') {
            this.dataList = data.list
            this.totalPage = data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
          this.$refs.addOrUpdate.getRoleList()
          this.$refs.addOrUpdate.getJobList()
        })
      },
      jobBtn () {
        this.addOrUpdateVisibles = true
        this.$nextTick(() => {
          this.$refs.staffAdmin.getJobList()
        })
      },
      upwd (id) {
        this.ispasswordPop = true
        this.$nextTick(() => {
          this.$refs.passwordPop.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm(
          `删除之后数据不可恢复，对应数据也会清理。`,
          '确定删除该商家账户？',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).then(() => {
          this.$http({
            url: this.$http.adornUrl('/admin/business/delete?id=' + id),
            method: 'post',
            data: this.$http.adornData({
              id: id
            })
          }).then(({ data }) => {
            if (data && data.code === '200') {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
  </script>
  